package cn.xfdzx.android.apps.shop.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.AfterServiceInfoActivity;
import cn.xfdzx.android.apps.shop.activity.ShopActivity;
import cn.xfdzx.android.apps.shop.bean.AfterSalesListRetailBean;
import cn.xfdzx.android.apps.shop.bean.OrderListBeen;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.widget.CornerImageView;

/**
 * Creator: zf.
 * Date: 2020/9/28.
 * Description:批发申请退款商品列表选择页面适配器.
 */
public class AfterServiceMarketGoodsAdapter extends BaseQuickAdapter<OrderListBeen.DataBean.CartInfoBean, BaseViewHolder>  {
    private OnItemOnClickListener onItemOnClickListener;
    private List<OrderListBeen.DataBean.CartInfoBean> cartInfo;//列表
    public AfterServiceMarketGoodsAdapter(@Nullable List<OrderListBeen.DataBean.CartInfoBean> data) {
        super(R.layout.item_aftermarketgoods, data);
        this.cartInfo = data;
    }

    @Override
    public void setData(int index, @NonNull OrderListBeen.DataBean.CartInfoBean data) {
        super.setData(index, data);
    }


    @Override
    protected void convert(final BaseViewHolder viewHolder, final OrderListBeen.DataBean.CartInfoBean date) {
        CheckBox checkbox = viewHolder.getView(R.id.checkbox);
        CornerImageView iv_goods = viewHolder.getView(R.id.iv_goods);
        iv_goods.setType(CornerImageView.TYPE_ROUND);

        ImageGlideUtil.loadImage(mContext,iv_goods,date.getProductInfo().getImage());
        viewHolder.setText(R.id.tv_goods_name,date.getProductInfo().getStore_name())
        .setText(R.id.tv_goodssize,"包装规格: "+date.getProductInfo().getUnit_name() )
        .setText(R.id.tv_goodsnum,"x"+date.getCart_num());

        checkbox.setChecked(date.isAfterCheck());
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!buttonView.isPressed()) { //判断view是否是用户点击
                    return;
                }
                cartInfo.get(viewHolder.getLayoutPosition()).setAfterCheck(isChecked);
                onItemOnClickListener.onItemCheckClick(viewHolder.getLayoutPosition(),date);
            }
        });
    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<OrderListBeen.DataBean.CartInfoBean> list){
        this.cartInfo = list;
        super.replaceData(list);
    }

    public void setItemCheckListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemCheckClick(int position, OrderListBeen.DataBean.CartInfoBean date);
    }

}
